package com.mioto.ld.communication.mqtt.protocol.model;

import cn.hutool.core.collection.CollUtil;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import lombok.AllArgsConstructor;
import lombok.Builder;

import java.util.Map;

/**
 * @author mioto-qinxj
 * @date 2024/5/30
 * @desc 告警记录产生条件对象
 */
@Builder
@AllArgsConstructor
public class AlertLogCondition {
    /**
     * 设备上报属性
     */
    private Map<String,Object> reportAttribute;
    /**
     * 设备上报故障
     */
    private Map<Integer,String> reportFault;

    public String toJsonStr(){
        Gson gson = new Gson();
        JsonObject jsonObject = new JsonObject();
        if (CollUtil.isNotEmpty(reportAttribute)){
            reportAttribute.remove("reportTime");
            jsonObject.add("reportAttribute", gson.toJsonTree(reportAttribute));
        }
        if (CollUtil.isNotEmpty(reportFault)){
            jsonObject.add("reportFault", gson.toJsonTree(reportFault));
        }

        return jsonObject.toString();
    }


}
